package com.cskaoyan.controller;

import com.cskaoyan.bean.baseresultVO.BaseParam;
import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.domain.Comment;
import com.cskaoyan.bean.goods.BasePageData;
import com.cskaoyan.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @BelongProject: mall35th
 * @BelongPackage: com.cskaoyan.controller
 * @Author: zijin
 * @Createtime: 2021-12-01 星期三 11:23
 * @Description: 评论
 */
@RestController
public class CommentController {
    @Autowired
    CommentService commentService;
    /**
     * http://182.92.235.201:8083/admin/comment/list?page=1&limit=20&userId=1&valueId=1020000&sort=add_time&order=desc
     * @param userId 用户id
     * @param valueId 商品id
     * @param pageParams
     * @return
     */
    @RequestMapping("admin/comment/list")
    public BaseRespVo<BasePageData<Comment>> list(Integer userId, Integer valueId, BaseParam pageParams){
        BasePageData<Comment> basePageData = commentService.queryCommentsByCondition(userId,valueId,pageParams);
        return BaseRespVo.ok(basePageData);
    }

    @RequestMapping("admin/order/reply")
    public BaseRespVo reply(@RequestBody Map map){
        Integer commentId = (Integer) map.get("commentId");
        String content = (String) map.get("content");
        commentService.replyComment(commentId,content);
        return BaseRespVo.ok(null);
    }

    @RequestMapping("admin/comment/delete")
    public BaseRespVo delete(@RequestBody Comment comment){
        commentService.deleteComment(comment);
        return BaseRespVo.ok(null);
    }

}
